package com.Util;

import com.Common.Result;
import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @description:
 * @author: hkw14
 * @time: 2021/4/28 15:19
 */
public class RespUtil {
    /**
     * @description: 根据HttpServletResponse对象，将数据使用Json格式返回
     * @Params: * @param resp
     * @param rs
     * @return: void
     * @author: hkw14
     * @time: 2021/4/28 15:23
     */
    public static void write(HttpServletResponse resp, Result rs){
        //设置编码
        resp.setContentType("text/json;charset=UTF-8");
        PrintWriter writer = null;
        try {
            writer = resp.getWriter();
            writer.print(JSON.toJSONString(rs));
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            writer.close();
        }

    }
}
